<template>
	<view class="container">
		<view class="visitor">
			<view class="outside">
				<view class="within">
					<view class="info">
						<view class="name">
							<text>{{infoData.name}}</text>
							<!-- <text class="classType">【门诊】</text> -->
							<view class="btn m-l-30" @click="showVisitCard=true">
								<img src="@/static/images/qiehuan.png" style="width:29rpx;margin-right:8rpx;"></img>
								切换就诊人
							</view>
						</view>
						<view class="cord">
							卡号
						</view>
						<view>{{$desensitizationNormalStr(infoData.idNum)}}</view>
					</view>
				</view>
			</view>
		</view>
		<!-- <view class="visitor">
		<view class="info">
			<view>姓名：{{infoData.name}}</view>
			<view style="color:rgba(0,0,0,0.45)">卡号：{{infoData.idNum}}</view>
		</view>
		<view class="btn" @click="showVisitCard=true">
			切换就诊人
		</view>
	</view> -->
		<view class="screenType">
			<view class="typeLeft" @click="showpop">
				{{timesRange}}
				<u-icon name="arrow-down-fill" color="#fff" size="10"></u-icon>
			</view>
			<view class="typeRight" @click="showTypes">
				{{typesName}}
				<u-icon name="arrow-down-fill" color="#fff" size="10"></u-icon>
			</view>
		</view>
		<view class="list">
			<scroll-view class="scroll-view_H" scroll-y="true" style="height: calc(100vh - 118rpx);">
				<view class="items">
					<view class="title">
						<text class="names">超声检查报告单超声检查报告单超声检查报告单超声检查报告单</text>
						<view class="btn">
							待支付
						</view>
					</view>
					<view class="name">
						<text class="left">就诊人</text>
						<text>张岚</text>
					</view>
					<view class="icd">
						<text class="left">开单时间</text>
						<text>2023-08-11 09:25:30</text>
					</view>
					<view class="time">
						<text class="left">需付款</text>
						<text class="moneyw">共一项<text class="money">￥</text><text class="nums">99.00</text></text>
					</view>
					<view class="dept">
						<text class="left"></text>
						<text class="payBtn">去支付</text>
					</view>
				</view>
			</scroll-view>
		</view>
		<u-picker keyName="label" :show="showType" @cancel='showType=false' :closeOnClickOverlay='true'
			@close="showType=false" :columns="columns" @confirm="confirm"></u-picker>
		<liuCalendarDate ref="calendar2" isRange @checked='changeTime'></liuCalendarDate>
		<!-- 切换就诊人 -->
		<u-popup :show="showVisitCard" :round="10" :safeAreaInsetBottom="true" mode="bottom">
			<switchVisitCard :visitData="visitList" :relations="relationTrans" @closeVisit="close" />
		</u-popup>
	</view>
</template>

<script>
	import {
		getPatientBaseList
	} from "@/api/card/index.js"
	import {
		getPayMentList
	} from "@/api/pay/index.js"
	import switchVisitCard from '@/components/switchVisitCard/index.vue';
	import liuCalendarDate from '@/components/liu-calendar-date/liu-calendar-date.vue';
	import {
		getDictType
	} from "@/api/system/public.js";

	export default {
		components: {
			switchVisitCard,
			liuCalendarDate
		},
		data() {
			return {
				infoData: {},
				timesRange: '全部时间',
				typesName: '待支付',
				showTime: false,
				visitList: [],
				showVisitCard: false,
				relationTrans: {},
				showType: false,
				beginDate: '',
				endDate: '',
				checkType: '',
				columns: [
					[{
						label: '待支付',
						id: '0'
					}, {
						label: '已支付',
						id: '1'
					}]
				],
				openid: '',
			}
		},
		onLoad(options) {
			let openid = uni.getStorageSync('openid') || ''
			this.openid = openid
			if (uni.getStorageSync('currentVisitCard')) {
				this.infoData = JSON.parse(uni.getStorageSync('currentVisitCard'))
			}
			this.checkType = '0'
			this.getCardList()
			this.getDict()
			this.getList()
		},
		methods: {
			getCardList() {
				let params = {
					hospitalCode: JSON.parse(uni.getStorageSync('hospital')).hospitalCode,
					openId: this.openid
				}
				getPatientBaseList(params).then(res => {
					if (res.code == 200) {
						this.visitList = res.rows
					}
				})
			},
			getList() {
				let obj = {
					realName: this.infoData.name,
					patientCard: this.infoData.idNum,
					bz: this.checkType,
					beginDate: this.beginDate,
					endDate: this.endDate
				}
				getPayMentList(obj).then(res => {
					console.log(res, 111)
				})
			},
			goDtl(item) {
				uni.navigateTo({
					url: '/pages/mine/reservation/dtlView'
				})
			},
			close() {
				this.showVisitCard = false
			},
			confirm(e) {
				this.typesName = e.value[0].label
				this.checkType = e.value[0].id
				this.showType = false
			},
			showTypes() {
				this.showType = true
			},
			showpop() {
				this.$refs.calendar2.open()
			},
			changeTime(time) {
				this.timesRange = time.value[0] + '至' + time.value[1]
				this.beginDate = time.value[0]
				this.endDate = time.value[1]
				console.log(time)
			},
			/* 字典 */
			getDict() {
				getDictType({
					dictType: 'sys_relation'
				}).then(res => {
					console.log(res)
					if (res.code == 200) {
						res.rows.forEach(item => {
							this.relationTrans[item.dictValue] = item.dictLabel
						})
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: rgb(245, 245, 245);
	}

	.list {
		padding: 24rpx;
		margin: 0 auto;

		.items {
			background-color: #fff;
			border-radius: 8px;
			margin-bottom: 24rpx;
			padding-bottom: 12rpx;

			.title {
				padding: 24rpx;
				display: flex;
				font-size: 32rpx;
				font-weight: 600;
				align-items: center;
				border-bottom: 1rpx solid #eee;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.names {
					flex: 1;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
				}

				.btn {
					width: 100rpx;
					font-size: 28rpx;
					color: #FF6430;
					text-align: right;
				}
			}

			.name,
			.icd,
			.time,
			.dept {
				display: flex;
				justify-content: space-between;
				padding: 12rpx 24rpx;
				font-size: 28rpx;

				.left {
					color: #999;
					width: 130rpx;
				}

				.payBtn {
					border-radius: 20px;
					background-color: #4D8EFF;
					color: #fff;
					padding: 8rpx 24rpx;
					text-align: center;
				}

				.moneyw {
					display: flex;
					font-size: 24rpx;
					color: #999;

					.money {
						color: #000;
					}

					.nums {
						font-size: 40rpx;
						color: #000;
					}
				}
			}
		}
	}

	.screenType {
		width: 100%;
		display: flex;
		align-items: center;
		padding: 20rpx;
		background-color: rgb(92, 147, 249);
		justify-content: space-around;
		color: #fff;

		.typeLeft,
		.typeRight {
			display: flex;
			align-items: center;
		}
	}

	.visitor {
		width: 100%;
		// background-color: rgb(92, 147, 249);
		background: url('@/static/images/report-small-bg.png') no-repeat left center, linear-gradient(180deg, rgba(197, 218, 255, 1) 0%, rgba(92, 147, 249, 1) 100%);
		background-size: auto 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 24rpx 24rpx 0 24rpx;
		color: #3C537D;

		.outside {
			width: 100%;
			background-color: #fff;
			padding: 12rpx 12rpx 0 12rpx;
			border-radius: 8px 8px 0 0;
			background: url('@/static/images/card_bg.png') no-repeat;
			background-size: 100% 100%;

			.within {
				border-radius: 8px 8px 0 0;

				.info {
					padding: 16rpx 28rpx 20rpx;
					font-size: 34rpx;

					.name {
						display: flex;
						align-items: center;

						.classType {
							display: inline-block;
							margin: 0 36rpx;
						}

						.btn {
							font-size: 28rpx;
							padding: 7rpx 14rpx;
							background: linear-gradient(90deg, rgba(77, 142, 255, 1) 0%, rgba(94, 150, 247, 1) 100%);
							color: #fff;
							display: flex;
							align-items: center;
							border-radius: 5px;
						}
					}

					.cord {
						font-size: 28rpx;
						padding: 16rpx 0 8rpx;
					}
				}
			}
		}
	}
</style>